package com.xinyun.server.protocol.receive;

import com.xinyun.server.protocol.ProtocolData;
import com.xinyun.server.protocol.ProtocolDataHeader;
import com.xinyun.server.util.Utils;
import io.netty.buffer.ByteBuf;

/**
 * Created by bubusy on 16/5/22.
 */
public class RegisterBoardId extends ProtocolData {

    public String boardId;
    public String time;

    public RegisterBoardId(ProtocolDataHeader header, ByteBuf bodyBytes) {

        super(header, bodyBytes);

    }

    public static RegisterBoardId parseFromProtocolData(ProtocolData protocolData) {
        RegisterBoardId obj = new RegisterBoardId(protocolData.getHeader(), protocolData.getBodyBytes());
        ByteBuf body = protocolData.getBodyBytes().copy();
        String boardId = "";
        for (int i = 0; i < 9; i++) {
            int v = body.readByte();
            if (v < 10) {
                boardId = boardId + "0" + v;//补0
            } else {
                boardId = boardId + v;
            }
        }

        obj.boardId = boardId;

        String dateStr = Utils.parseTime(body);
        obj.time = dateStr;

        return obj;
    }

}
